package com.manyiaby.view.viewutils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;

/**
 * Created by yx on 2017/8/18.
 * 调用手机权限设置界面
 */

public class PowerSetUtils {

    public static void goPowerSetting(Context context) {
        /**
         * -----------------------------------跳转到 vivo 的权限管理页面
         * 点击设置图标>加速白名单>我的app>点击软件管理>软件管理权限>软件>我的app>信任该软件
         */
        Intent appIntent = context.getPackageManager().getLaunchIntentForPackage("com.iqoo.secure");
        if (appIntent != null) {
            context.startActivity(appIntent);
            ActivityOpenAnimation.push_In_Out(context);
            //floatingView = new SettingFloatingView(this, "SETTING", getApplication(), 0);
            //floatingView.createFloatingView();
            return;
        }

        /**
         * -----------------------------------跳转到 vivo 的权限管理页面
         * oppo 点击设置图标>应用权限管理>按应用程序管理>我的app>我信任该应用>点击权限隐私>自启动管理>我的app
         */
        appIntent = context.getPackageManager().getLaunchIntentForPackage("com.oppo.safe");
        if (appIntent != null) {
            context.startActivity(appIntent);
            ActivityOpenAnimation.push_In_Out(context);
            //floatingView = new SettingFloatingView(this, "SETTING", getApplication(), 1);
            //floatingView.createFloatingView();
            return;
        }

        /**
         * -----------------------------------跳转到miui的权限管理页面
         */
        Intent i = new Intent("miui.intent.action.APP_PERM_EDITOR");
        ComponentName componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
        i.setComponent(componentName);
        i.putExtra("extra_pkgname", context.getPackageName());
        try {
            context.startActivity(i);
            ActivityOpenAnimation.push_In_Out(context);
        } catch (Exception e) {
            //e.printStackTrace();
            /**
             * -------------------------------跳转到魅族的权限管理系统
             */
            Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.putExtra("packageName", context.getPackageName());
            try {
                context.startActivity(intent);
                ActivityOpenAnimation.push_In_Out(context);
            } catch (Exception e2) {
                //e2.printStackTrace();
                try {
                    /**
                     * ------------------------华为的权限管理页面
                     */
                    Intent intenth = new Intent();
                    intenth.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");//华为权限管理
                    intenth.setComponent(comp);
                    context.startActivity(intenth);
                    ActivityOpenAnimation.push_In_Out(context);
                } catch (Exception e3) {
                    //e3.printStackTrace();
                    /**
                     * -------------------------打开所有原生系统设置界面
                     */
                    Intent localIntent = new Intent();
                    localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    if (Build.VERSION.SDK_INT >= 9) {
                        localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                        localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
                    } else if (Build.VERSION.SDK_INT <= 8) {
                        localIntent.setAction(Intent.ACTION_VIEW);
                        localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
                        localIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
                    }
                    context.startActivity(localIntent);
                    ActivityOpenAnimation.push_In_Out(context);
                }
            }
        }


    }


}
